using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameForKids
{
    class BilliardBall
    {
        public Vector2 Position;
        public int Range;
        public Vector2 Velocity;
        public float Accelerometer;

        public string BallLink = "BilliardGame/Images/Ball";

        public BilliardBall(Vector2 position, int range)
        {
            Position = position;
            Range = range;
            Velocity = Vector2.Zero;
            Accelerometer = 0.98f;
        }

        public void Update(GameTime gameTime)
        {
            Position += Velocity;
            Velocity *= Accelerometer;
            if (Velocity.Length() < 1.0f)
            {
                Velocity = Vector2.Zero;
            }
        }

        public void Draw(SpriteBatch batch)
        {
            batch.Draw(Suport.GetTexture(BallLink), new Vector2(Position.X - Range, Position.Y - Range), Color.White);
        }

        public bool CheckTouch(Vector2 touchPoint)
        {
            if (Math.Sqrt((Position.X - touchPoint.X) * (Position.X - touchPoint.X) + (Position.Y - touchPoint.Y) * (Position.Y - touchPoint.Y)) <= Range)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool IsHitWith(Vector2 pos, float r)
        {
            if ((pos - Position).Length() <= r + Range)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public Vector2 HitDangeUnit(Vector2 pos)
        {
            return (pos - Position) / (pos - Position).Length();
        }

    }
}
